package com.mf.ergate.controller.bo.pt;

import com.mf.ergate.api.bo.pt.PtOrderHelpSendRemoteService;
import com.mf.ergate.api.bo.pt.model.dto.PtOrderHelpSendCreateDto;
import com.mf.ergate.api.bo.pt.model.dto.PtOrderHelpSendDeleteDto;
import com.mf.ergate.api.bo.pt.model.dto.PtOrderHelpSendQueryDto;
import com.mf.ergate.api.bo.pt.model.dto.PtOrderHelpSendUpdateDto;
import com.mf.ergate.api.bo.pt.model.vo.PtOrderHelpSendVo;
import com.mf.ergate.common.utils.MfBeanUtils;
import com.mf.ergate.domain.model.bo.pt.PtOrderHelpSendEntity;
import com.mf.ergate.service.bo.pt.PtOrderHelpSendService;
import com.mf.framework.common.model.Page;
import com.mf.framework.common.model.RemotePage;
import com.mf.framework.common.model.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 跑腿订单帮送Controller
 * User: zhaoming
 * DateTime: 2019-01-28
 * To change this template use File | Settings | File Templates.
 */
@RestController
public class PtOrderHelpSendController implements PtOrderHelpSendRemoteService {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private PtOrderHelpSendService ptOrderHelpSendService;

    /**
     * 新增
     * @param ptOrderHelpSendCreateDto 跑腿订单帮送新增Dto
     * @return 跑腿订单帮送
     */
    public Result<PtOrderHelpSendVo> insert(@RequestBody PtOrderHelpSendCreateDto ptOrderHelpSendCreateDto) {
        PtOrderHelpSendEntity ptOrderHelpSendEntity = MfBeanUtils.copyObject(ptOrderHelpSendCreateDto, PtOrderHelpSendEntity.class);
        ptOrderHelpSendEntity = ptOrderHelpSendService.insert(ptOrderHelpSendEntity);
        PtOrderHelpSendVo ptOrderHelpSendVo = MfBeanUtils.copyObject(ptOrderHelpSendEntity, PtOrderHelpSendVo.class);
        return new Result<>(ptOrderHelpSendVo);
    }

    /**
     * 根据唯一编号更新
     * @param ptOrderHelpSendUpdateDto 跑腿订单帮送更新Dto
     * @return 执行结果
     */
    public Result<Boolean> updateByUniqueNo(@RequestBody PtOrderHelpSendUpdateDto ptOrderHelpSendUpdateDto) {
        PtOrderHelpSendEntity ptOrderHelpSendEntity = MfBeanUtils.copyObject(ptOrderHelpSendUpdateDto, PtOrderHelpSendEntity.class);
        Boolean flag = ptOrderHelpSendService.updateByUniqueNo(ptOrderHelpSendEntity);
        return new Result<>(flag);
    }

    /**
     * 根据唯一编号删除(逻辑删除)
     * @param ptOrderHelpSendDeleteDto 跑腿订单帮送删除Dto
     * @return 结果集
     */
    public Result<Boolean> deleteByUniqueNo(@RequestBody PtOrderHelpSendDeleteDto ptOrderHelpSendDeleteDto){
        PtOrderHelpSendEntity ptOrderHelpSendEntity = MfBeanUtils.copyObject(ptOrderHelpSendDeleteDto, PtOrderHelpSendEntity.class);
        Boolean flag = ptOrderHelpSendService.deleteByUniqueNo(ptOrderHelpSendEntity);
        return new Result<>(flag);
    }

    /**
     * 根据唯一编号查询
     * @param uniqueNo 唯一编号
     * @return 跑腿订单帮送
     */
    public Result<PtOrderHelpSendVo> selectByUniqueNo(@RequestBody String uniqueNo) {
        PtOrderHelpSendEntity ptOrderHelpSendEntity = ptOrderHelpSendService.selectByUniqueNo(uniqueNo);
        PtOrderHelpSendVo ptOrderHelpSendVo = MfBeanUtils.copyObject(ptOrderHelpSendEntity, PtOrderHelpSendVo.class);
        return new Result<>(ptOrderHelpSendVo);
    }

    /**
     * 根据条件查询
     * @param ptOrderHelpSendQueryDto 跑腿订单帮送查询Dto
     * @return 跑腿订单帮送列表
     */
    public Result<List<PtOrderHelpSendVo>> selectByCondition(@RequestBody PtOrderHelpSendQueryDto ptOrderHelpSendQueryDto) {
        List<PtOrderHelpSendEntity> ptOrderHelpSendEntities = ptOrderHelpSendService.selectByCondition(ptOrderHelpSendQueryDto);
        List<PtOrderHelpSendVo> ptOrderHelpSendVos = MfBeanUtils.copyList(ptOrderHelpSendEntities, PtOrderHelpSendVo.class);
        return new Result<>(ptOrderHelpSendVos);
    }

    /**
     * 根据条件查询数量
     * @param ptOrderHelpSendQueryDto 跑腿订单帮送查询Dto
     * @return 数量
     */
    public Result<Integer> selectCount(@RequestBody PtOrderHelpSendQueryDto ptOrderHelpSendQueryDto) {
        return new Result<>(ptOrderHelpSendService.selectCount(ptOrderHelpSendQueryDto));
    }

    /**
     * 根据条件分页查询
     * @param remotePage 远程分页对象
     * @return 跑腿订单帮送分页列表
     */
    public Result<Page<PtOrderHelpSendVo>> selectPage(@RequestBody RemotePage<PtOrderHelpSendQueryDto> remotePage){
        Page<PtOrderHelpSendEntity> ptOrderHelpSendEntityPage = ptOrderHelpSendService.selectPage(remotePage.getPage(), remotePage.getObj());
        Page<PtOrderHelpSendVo> page = MfBeanUtils.copyPage(ptOrderHelpSendEntityPage, PtOrderHelpSendVo.class);
        return new Result<>(page);
    }

}